| |
Integrate OpenFeint into your game
OpenFeint can be integrated into an existing Android app or it can be incorporated in your game
design from the start. Once you have been through the process of experimenting with OpenFeint features in the sample app using
your own product key, many of the steps for adding these features to your own
app will seem familiar.
NOTE: The following instructions were tested in Eclipse on the Hello World
sample app from the tutorial at http://developer.android.com.
- If your application is not already registered as an OpenFeint application:
- Go to the OpenFeint Developer Dashboard
Find it at https://api.openfeint.com/dd
- Register or Login
Use an email address for your identity with your chosen password.
- Select an existing game description or register a new one.

- Make a backup copy of your project before you start integrating with OpenFeint.
- Extract a fresh copy of the OpenFeint Android SDK project into a convenient temporary directory.
- Run Eclipse.
- Import the OpenFeintAPI and GameFeed libraries into your project:
- Right-click the application project.
- Click Import.
- Click Existing Projects into Workspace..
- Click Next.
- Browse to the directory in which the OpenFeintAPI and GameFeed libraries are stored.
- Click OK.
- If OpenFeintAPI is not yet imported, click its checkbox.
- If GameFeed is not yet imported, click its checkbox.
- Click Finish.
- Build the OpenFeint and GameFeed libraries.
- Import your application as a project into Eclipse.
- If they do not already exist, create assets/, gen/, libs/, and res/ directories in the root of your
project.
- Edit the AndroidManifest.xml file in your project:
- Add the following activities inside your <application> tag:
<activity android:name="com.openfeint.internal.ui.IntroFlow" android:label="IntroFlow" android:configChanges="orientation|keyboardHidden" android:theme="@style/OFNestedWindow"/>
<activity android:name="com.openfeint.api.ui.Dashboard" android:label="Dashboard" android:configChanges="orientation|keyboardHidden" android:theme="@style/OFNestedWindow"/> <activity android:name="com.openfeint.internal.ui.Settings" android:label="Settings" android:configChanges="orientation|keyboardHidden" android:theme="@style/OFNestedWindow"/> <activity android:name="com.openfeint.internal.ui.NativeBrowser" android:label="NativeBrowser" android:configChanges="orientation|keyboardHidden" android:theme="@style/OFNestedWindow"/>
- Add the following permissions to AndroidManifest.xml outside of your tag:
<uses-permission android:name="android.permission.INTERNET" />
- To grant OpenFeint the ability to save data in the /sdcard/, which is faster and uses less
of the user's built-in flash memory, add the following to the AndroidManifest.xml:
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
- To allow OpenFeint to retrieve the logged-in user's email address from Phone SDK version 5 or above so that the user does not have to type the email address in when creating an account, add the following to the AndroidManifest.xml:
<uses-permission android:name="android.permission.GET_ACCOUNTS" />
- To allow OpenFeint detect network connectivity state, which will allow it to notify the user when they can't login (instead of taking many seconds to time out), add the following to the AndroidManifest.xml:
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
- Refresh (File->Refresh) the project so that the items you added appear.
- Initialize OpenFeint in the onCreate() method of your Application object:
- If you haven't overridden the application object:
- Create a class that extends android.app.Application
- In AndroidManifest.xml, be sure to set the android:name attribute of your <application> element to the name of your application class. For example, in the OpenFeintExample project, the android:name of the <application> element is set to ".MyApplicationClassName".
- Construct your OpenFeint settings object using the game name, game ID, game key, and game secret of your game as defined on the OpenFeint developer site:
- The values can be set in the class definition of the source code of your Application:
static final String gameName = "Name of your application";
static final String gameID = "gameID";
static final String gameKey = "gameKey";
static final String gameSecret = "gameSecret";
For example, in the sample application, you could add these lines in src/com.openfeint.example/OpenFeintApplication.java after:
public class OpenFeintApplication extends Application {
Note: You must provide your game's name, key, secret, and id to
OpenFeintSettings. You can find these in the developer dashboard at
https://api.openfeint.com/dd. For instructions on retrieving your application settings, click here.
- Use the variables you defined to construct your settings object. This can be done in the onCreate() method of your main activity:
OpenFeintSettings settings = new OpenFeintSettings(gameName, gameKey, gameSecret, gameID);
For example, in the sample application, you could add this line into the onCreate() method in src/com.openfeint.example/OpenFeintApplication.java.
- Initialize OpenFeint in the onCreate() method of your application by adding the the following line into the onCreate() method in your source code:
OpenFeint.initialize(this, settings, new OpenFeintDelegate() {}); Make sure you call OpenFeint.initialize()
after you've set the values in the settings object.
- Run your application.
On the application's first launch, when it gets to the OpenFeint.initialize() call, it displays an OpenFeint welcome screen
over the game screen. This allows the user to log in to OpenFeint or decline OpenFeint.
After the first launch of the app, the user's choice is remembered and the OpenFeint welcome screen does not appear.
At this point, OpenFeint has only been initialized; none of its features have yet been incorporated into your application.
|